﻿using WWLauncher.Constant;
using WWLauncher.ViewModel;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;
namespace WWLauncher.Util
{
    public class BGSettingUtil
    {
        private static readonly AppConfig Config = MainViewModel.Instance().AppConfig;
        public static void BGSetting(Border bgBorder)
        {
            if (bgBorder == null)
            {
                return;
            }
            if (Config.ThemeConfig.BgStyle == BGStyle.ImgBac || Config.ThemeConfig.BgStyle == 0)
            {
                Image image = new Image
                {
                    Effect = new BlurEffect()
                    {
                        Radius = Config.BlurValue
                    },
                    Margin = new Thickness(-30),
                    Source = Config.BitmapImage,
                    Opacity = (double)(Math.Round((decimal)(Config.BgOpacity / 100.00), 2))
                };
               

                Grid grid = new Grid
                {
                    ClipToBounds = true
                };
                grid.Children.Add(image);

                VisualBrush vb = new VisualBrush
                {
                    Visual = grid
                };
                bgBorder.Background = vb;
            }
            else
            {
                LinearGradientBrush lgb = new LinearGradientBrush();
                GradientStop gs = new GradientStop
                {
                    Color = (Color)ColorConverter.ConvertFromString(Config.ThemeConfig.GradientBgParam.Color1)!,
                    Offset = 0
                };

                lgb.GradientStops.Add(gs);

                GradientStop gs2 = new GradientStop
                {
                    Color = (Color)ColorConverter.ConvertFromString(Config.ThemeConfig.GradientBgParam.Color2)!,
                    Offset = 1
                };
                lgb.GradientStops.Add(gs2);
                lgb.Opacity = Math.Round(Config.BgOpacity / 100.00, 2);
                bgBorder.Background = lgb;
            }

        }

    }
}
